package zifu;

import java.io.*;

public class copyDirec {
    public static void main(String[] args) throws IOException {
        copy1("D:\\study\\999.java拓展\\自己敲代码-git\\javaBase\\homeExtendDay13\\src\\main\\java\\zifu\\demo",
                "D:\\study\\999.java拓展\\自己敲代码-git\\javaBase\\homeExtendDay13\\src\\main\\java\\zifu\\demo2");
    }
    public static void copy1(String path,String ResPath) throws IOException {
        File file =  new File(path);
        if(ResPath !=null){
            File file1 = new File(ResPath);
            file1.mkdirs();
        }

            File[] files = file.listFiles();
        if(files !=null){
            for (int i = 0; i < files.length-1; i++) {
                File file1 = files[i];
                String absoluteFile = file1.getAbsolutePath();
                if(file1.isFile()){
                    readAndWriteFile(absoluteFile,ResPath);
                }else{
                    copy1(absoluteFile,ResPath);
                }
            }
        }

    }
    public  static void readAndWriteFile(String pathRes,String ResPath) throws IOException {
        FileInputStream fileInputStream = new FileInputStream(pathRes);
        byte[] arr = new byte[3];
        int readLen = 0;
        while (readLen !=-1){
            readLen = fileInputStream.read(arr);
            FileOutputStream fileOutputStream = new FileOutputStream(ResPath);
            fileOutputStream.write(arr);
        }
    }
}
